package com.google.gwt.gfx.client.graphics.svg;

import java.util.List;

import com.google.gwt.gfx.client.graphics.LinearRing;
import com.google.gwt.gfx.client.shared.Point;

public class SVGLinearRing extends LinearRing {

	public SVGLinearRing() {
		super(SVG.createElement("polygon"));
	}

	@Override
	protected void append(List<Point> points) {
		StringBuilder builder = new StringBuilder();

		for (Point position : points) {
			builder.append(" " + position.getLeft() + "," + position.getTop());
		}

		SVG.setElementProperty(
				getElement(),
				"points",
				SVG.getElementProperty(getElement(), "points")
						+ builder.toString());
	}

	@Override
	protected void append(Point point) {
		SVG.setElementProperty(
				getElement(),
				"points",
				SVG.getElementProperty(getElement(), "points") + " "
						+ point.getLeft() + "," + point.getTop());
	}

	@Override
	protected void update(List<Point> points) {
		StringBuilder builder = new StringBuilder();

		for (Point point : points) {
			builder.append(point.getLeft() + "," + point.getTop() + " ");
		}

		SVG.setElementProperty(getElement(), "points", builder.toString());
	}

}
